import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.ListIterator;

/**
 * @Description
 *
 */
class MyArray<T>{
    public Object[] array = new Object[10];
    public void setArray(int pos,T val){
        this.array[pos] = val;
    }
    public T getArray(int pos){
        return (T)this.array[pos];
    }
}
public class Test {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(0);
        list.add(1);
        list.add(2);
        list.add(3);
       // list.remove(new Integer(1));//方法过时了
        //list.add(2,3);
        System.out.println(list);
        System.out.println("====用for循环遍历数组====");
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i)+" ");
        }
        System.out.println("====用for-each来遍历数组====");
        for(Integer x:list){
            System.out.println(x+" ");
        }
        System.out.println("用迭代器1来遍历数组");
        Iterator<Integer> it = list.iterator();//下面两个迭代器的父类
        while(it.hasNext()){
            System.out.println(it.hasNext());//hasNext会打印这一个并自动跳到下一个数字
        }
        System.out.println("用迭代器2来打印数组");
        ListIterator<Integer> lit = list.listIterator();
        while(lit.hasNext()){
            System.out.println(lit.hasNext()+" ");
        }
        System.out.println("====用迭代器3来打印数组");
        ListIterator<Integer> litPrev = list.listIterator(list.size());//从后向前打印
        while(litPrev.hasPrevious()){
            System.out.println(litPrev.hasPrevious()+" ");
        }


    }
    public static void main1(String[] args) {
        MyArrayList myArrayList = new MyArrayList();
        myArrayList.add(1);
        myArrayList.add(2);
        myArrayList.add(2);
        myArrayList.add(4);

        //myArrayList.add(3,6);
        myArrayList.addFirst(0);
        myArrayList.addLast(0);
        myArrayList.remove(3);
        System.out.println(Arrays.toString(myArrayList.elem));

    }
}
